package com.ingenieria.industrial.service.implementacion;

import com.ingenieria.industrial.dao.implementacion.ProcesoDAO;
import com.ingenieria.industrial.dto.Proceso;
import com.ingenieria.industrial.service.diseño.IProcesoService;
import java.sql.SQLException;
import java.util.ArrayList;

public class ProcesoService extends BaseSimpleService implements IProcesoService {

    private ProcesoDAO dao;

    @Override
    public int insert(Proceso proceso) throws Exception {
        int results = -1;
        try {
            begin();
            results = dao.insert(proceso);
            commit();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
        return results;
    }

    @Override
    public int update(Proceso proceso) throws Exception {
        int results = -1;
        try {
            begin();
            results = dao.update(proceso);
            commit();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
        return results;
    }

    @Override
    public int delete(String cod_proc) throws Exception {
        int results = -1;
        try {
            begin();
            results = dao.delete(cod_proc);
            commit();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
        return results;
    }

    @Override
    public ArrayList<Proceso> getAll() throws Exception {
        try {
            begin();
            return dao.getAll();
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
    }

    @Override
    public Proceso getById(String cod_proc) throws Exception {
        try {
            begin();
            return dao.getById(cod_proc);
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
    }

    @Override
    public ArrayList<Proceso> getListxTipo(String tipo) throws Exception {
        try {
            begin();
            return dao.getListxTipo(tipo);
        } catch (Exception sos) {
            throw handleError(sos);
        } finally {
            handleRelease();
        }
    }

    @Override
    protected void initDAO() throws SQLException {
        dao = new ProcesoDAO(transact);
    }

}
